function createFly () {
  if (mpvuePlatform === 'wx') {
    const Fly = require('flyio/dist/npm/wx')
    return new Fly()
  }
  return null
}

function handleError (err) {
  console.log('捕获异常')
  console.log(err)
  mpvue.showToast({
    title: '发生错误,详细信息见console',
    icon: 'none',
    duration: 1500,
    mask: true
  })
}

export function get (url, params = {}) {
  const fly = createFly()
  if (fly) {
    return new Promise((resolve, reject) => {
      fly.get(url, params).then(response => {
        if (response && response.data && response.data.error_code === 0) {
          // 对请求到的数据进行校验，返回的数据符合要求
          resolve(response)
        } else {
          reject(response)
        }
      }).catch(err => {
        handleError(err)
        reject(err)
      })
    })
  }
}
export function post (url, params = {}) {
  const fly = createFly()
  if (fly) {
    return new Promise((resolve, reject) => {
      fly.post(url, params).then(response => {
        resolve(response)
      }).catch(err => {
        handleError(err)
        reject(err)
      })
    })
  }
}
